﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

using CSF.BusinessCore.Data;
using Ict.DataAccess;
using Ict.DataAccess.Linq;

namespace CSF.BusinessCore.BLL
{
    /// <summary>
    /// 实现更新时记录修改者和修改时间的业务基类，同时也继承创建者业务逻辑
    /// </summary>
    /// <typeparam name="TEntity">实体类类型</typeparam>
    public abstract class LogModifyLogic<TEntity> : LogCreateLogic<TEntity>
        where TEntity : ILogCreate, ILogModify
    {
        /// <summary>
        /// 使用指定执行器，更新符合条件的记录(指定字段更新)
        /// </summary>
        /// <typeparam name="TElement">字段表类型</typeparam>
        /// <param name="t">数据类实例</param>
        /// <param name="selector">字段表</param>
        /// <param name="predicate">更新条件</param>
        /// <param name="exec">执行器实例</param>
        /// <returns>更新记录数</returns>
        public override int Update<TElement>(TEntity t,
            Expression<Func<TEntity, TElement>> selector,
            Expression<Func<TEntity, bool>> predicate,
            Executor exec)
        {
            if (string.IsNullOrWhiteSpace(t.ModifyBy))
                throw new NoModifyByException();

            t.ModifyTime = DateTime.Now;

            return base.Update(t, selector, predicate, exec);
        }
    }
}
